//
//  YDOAAcuteApplyVC.swift
//  YDOAProduct
//
//  Created by 占益民 on 2017/11/24.
//  Copyright © 2017年 Allen. All rights reserved.
//

import UIKit
import Toaster
class YDOAAcuteApplyVC: UIViewController {

    
    @IBOutlet weak var nameTf: UITextField! //物品名称
    
    @IBOutlet weak var guigeTf: UITextField! //规格
    
    @IBOutlet weak var unitTf: UITextField! //单位
    
    @IBOutlet weak var quantityTf: UITextField! //数量
    
    @IBOutlet weak var predictionPriceTf: UITextField!//预估单价
    
    
    @IBOutlet weak var remarkTf: UITextField! // 备注
    
    
    var type : Int! // 0  为急性物资申请     1  固定资产申请
    
    //提交申请
    @IBAction func sendApply(_ sender: Any) {
        view.endEditing(true)
        YMLog.log(item: "提交申请")
        if nameTf.text! == ""          ||
           guigeTf.text! == ""         ||
            unitTf.text! == ""         ||
           quantityTf.text! == ""      ||
        predictionPriceTf.text! == ""  ||
            remarkTf.text == ""           {
            Toast(text: "请填写完整再发起申请", delay: 0, duration: 1.5).show()
            return
        }else{
            let userinfo = UserDefaults.standard.object(forKey: USERINFO) as! [String:AnyObject]
            let uid =  userinfo["id"]!
            let urlStr = String(format:PUSH_ACTUE,uid as! CVarArg,nameTf.text!,guigeTf.text!,unitTf.text!,quantityTf.text!,predictionPriceTf.text!,remarkTf.text!)
            YMLog.log(item: urlStr)
            YMNetworkManager().getRequest(urlString: urlStr, params: nil, success: { (responser) in
                if responser["status"]?.int8Value == 1{
                    Toast.init(text: responser["message"] as? String, delay: 0, duration: 1.5)
                }else{
                    Toast.init(text: responser["message"] as? String, delay: 0, duration: 1.5)
                }
                
            }, failture: { (error) in
                
            })
        }
        
    }
    
    
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        if self.type == 0 {
             title = "临时急性物品申请"
        }else{
            title = "固定资产物资申购"
        }
       
        self.navigationController?.navigationBar.isHidden = false
        self.automaticallyAdjustsScrollViewInsets = false
        self.edgesForExtendedLayout = .init(rawValue: 0)
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        view.endEditing(true)
    }

}


extension YDOAGoodsApplyVC : UITextFieldDelegate {
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
}

